import sys
from PySide6.QtWidgets import (QApplication, QMainWindow, QMdiArea, QMdiSubWindow,
                             QTextEdit, QToolBar,QFileDialog)
from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon,QAction


class SubWindow(QMdiSubWindow):
    """单个文档子窗口，内部随便放任何控件"""
    _seq = 0                       # 类变量，给新窗口编号

    def __init__(self):
        super().__init__()
        SubWindow._seq += 1
        self.setWidget(QTextEdit())   # 这里换成你的图像标注 widget
        self.setWindowTitle(f"Document {SubWindow._seq}")
        self.resize(640, 480)


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("PyQt MDI Demo")
        self.resize(1200, 800)

        # 1. 创建 MDI 区域
        self.mdi = QMdiArea()
        self.setCentralWidget(self.mdi)

        # 2. 工具栏
        bar = QToolBar("File")
        self.addToolBar(bar)

        new_act = QAction("New", self)
        new_act.triggered.connect(self.new_doc)
        bar.addAction(new_act)

        cascade_act = QAction("Cascade", self)
        cascade_act.triggered.connect(self.mdi.cascadeSubWindows)
        bar.addAction(cascade_act)

        tile_act = QAction("Tile", self)
        tile_act.triggered.connect(self.mdi.tileSubWindows)
        bar.addAction(tile_act)

    # 3. 新建子窗口
    def new_doc(self):
        sub = SubWindow()
        self.mdi.addSubWindow(sub)
        sub.show()



if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = MainWindow()
    win.show()

    file_path, _ = QFileDialog.getOpenFileName(
    parent=None,                       # 父窗口，可为 None
    caption="Select File",            # 标题
    dir=".",                          # 起始目录
    filter="Text Files (*.txt);;All Files (*)"  # 文件过滤器
)

if file_path:                         # 用户真的选了文件
    print(file_path)

    sys.exit(app.exec())